package Java道题;

import java.util.Scanner;

public class Lianxi7 {
	/*
	 * 题目：输入一行字符，分别统计出其中英文字母、空格、数字和其它字符的个数
	 * */
	public static boolean Isletter(char n)
	{
		if(n>='A'&&n<='Z'||n>='a'&&n<='z')
		{
			return true;
		}
		else
		{
			return false;
		}

	}
	public static boolean Isdigit(char n)
	{
		if(n>='1'&&n<='9')
		{
			return true;
		}
		else
		{
			return false;
		}

	}
	public static boolean Isbackspace(char n)
	{
		if(n==' ')
		{
			return true;
		}
		else
		{
			return false;
		}

	}
	public static void statistics(char n[])
	{
		int i=0;
		int digit = 0,backspace = 0,letter = 0,other=0;
		while(i<n.length)
		{
			if(Isdigit(n[i]))
			{
				digit++;
			}
			else if(Isletter(n[i]))
			{
				letter++;
			}
			else if(Isbackspace(n[i]))
			{
				backspace++;
			}
			else
			{
				other++;
			}
			i++;
		}
		System.out.print("字母个数： "+letter+'\n'+"数字个数： "+digit+'\n'+"空格个数： "+backspace
				+'\n'+"其它个数: "+other);
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner ss=new Scanner(System.in);
		System.out.print("请输入一串字符串: ");
		String  a=ss.nextLine();
		char n[]=a.toCharArray();
		statistics(n);

	}

}
